package code5;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Client {

    public static void main(String[] args) {

        BufferedReader br = null;
        PrintStream ps = null;
        Scanner sc = null;

        try {
            Socket s = new Socket("127.0.0.1", 8888);
            System.out.println("连接服务器成功！");

            br = new BufferedReader(new InputStreamReader(s.getInputStream()));
            ps = new PrintStream(s.getOutputStream());
            sc = new Scanner(System.in);

            // 该线程用于接收任务台输入的信息以及向服务器发送信息
            Thread t1 = new ClientSendInformation(br, ps, sc);
            t1.start();
            // 该线程用于接收服务器发送的信息和文件
            Thread t2 = new ClientReceivedInformation(br);
            t2.start();
            t1.join();
            t2.join();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            if(null!=sc){
                sc.close();
            }
            if(null!=ps){
                ps.close();
            }
            if(null!=br){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
